<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>五下第11课《查表计算》自动售货机</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link rel="icon" href="favicon.ico" type="image/x-icon">
  <style>
      .gradient-bg {
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      }
      
      .card-effect {
          background: rgba(255, 255, 255, 0.95);
          border: 1px solid rgba(0, 0, 0, 0.1);
          backdrop-filter: blur(10px);
      }
      
      .bounce-in {
          animation: bounceIn 0.6s ease-out;
      }
      
      @keyframes bounceIn {
          0% {
              transform: scale(0.3);
              opacity: 0;
          }
          50% {
              transform: scale(1.05);
          }
          70% {
              transform: scale(0.9);
          }
          100% {
              transform: scale(1);
              opacity: 1;
          }
      }
      
      .pulse-animation {
          animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
      }
      
      @keyframes pulse {
          0%, 100% {
              opacity: 1;
          }
          50% {
              opacity: .5;
          }
      }
  </style>
</head>
<body class="gradient-bg min-h-screen flex items-center justify-center">
    <div class="absolute inset-0 bg-black opacity-10"></div>
    
    <!-- 游戏内容 -->
    <div id="gameContent" relative z-10>
        <div class="card-effect rounded-2xl p-8 shadow-2xl text-center w-full max-w-4xl mx-4">
            <!-- 游戏标题 -->
            <div class="mb-6">
                <h1 class="text-4xl font-bold text-gray-800 mb-2">🛒 自动售货机</h1>
                <p class="text-gray-600">五下第11课《查表计算》</p>
            </div>
            
            <!-- 提示信息 -->
            <div class="bg-blue-50 border border-blue-200 text-blue-800 p-4 rounded-lg mb-6">
                <div class="flex items-start">
                    <div class="flex-shrink-0">
                        <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                    </div>
                    <div class="text-left">
                        <p class="font-medium mb-1">操作步骤：</p>
                        <ul class="list-disc list-inside space-y-1 text-sm">
                            <li>第1步：点击想选购的货品</li>
                            <li>第2步：点击确认付款</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <!-- 自动售货机模拟区域 -->
            <div class="relative mx-auto" style="width: 638px; height: 961px;">
                <img src="auto_selling/selling_machine2.png" alt="自动售货机" class="w-full h-full rounded-xl shadow-lg">
                
                <!-- 价格显示区域 -->
                <div id="priceDisplay" class="bg-gray-800 bg-opacity-90 text-white p-3 absolute rounded-lg flex items-center justify-center text-xl font-bold" style="top: 120px; left: 455px; width: 150px; height: 60px;">
                    <span class="mr-1">￥</span>
                    <span id="priceValue">0.00</span>
                </div>
                
                <!-- 第一行商品 -->
                <div class="absolute" style="top: 55px; left: 55px;">
                    <img src="auto_selling/百事可乐.jpg" alt="百事可乐" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="百事可乐" data-price="2.5" data-quantity="10">百事可乐</button>
                </div>
                
                <div class="absolute" style="top: 55px; left: 145px;">
                    <img src="auto_selling/尖叫.jpg" alt="尖叫" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="尖叫" data-price="4.8" data-quantity="8">尖叫</button>
                </div>
                
                <div class="absolute" style="top: 55px; left: 230px;">
                    <img src="auto_selling/可口可乐.jpg" alt="可口可乐" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="可口可乐" data-price="3.9" data-quantity="8">可口可乐</button>
                </div>
                
                <div class="absolute" style="top: 55px; left: 310px;">
                    <img src="auto_selling/脉动.jpg" alt="脉动" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="脉动" data-price="6.5" data-quantity="8">脉动</button>
                </div>
                
                <!-- 第二行商品 -->
                <div class="absolute" style="top: 180px; left: 55px;">
                    <img src="auto_selling/冰红茶.jpg" alt="冰红茶" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="冰红茶" data-price="1.0" data-quantity="10">冰红茶</button>
                </div>
                
                <div class="absolute" style="top: 180px; left: 145px;">
                    <img src="auto_selling/东方树叶.jpg" alt="东方树叶" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="东方树叶" data-price="4.2" data-quantity="8">东方树叶</button>
                </div>
                
                <div class="absolute" style="top: 180px; left: 230px;">
                    <img src="auto_selling/柑橘风味.jpg" alt="柑橘风味" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="柑橘风味" data-price="4.2" data-quantity="8">柑橘风味</button>
                </div>
                
                <div class="absolute" style="top: 180px; left: 310px;">
                    <img src="auto_selling/喜之郎.jpg" alt="喜之郎" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="喜之郎" data-price="2.5" data-quantity="8">喜之郎</button>
                </div>
                
                <!-- 第三行商品 -->
                <div class="absolute" style="top: 320px; left: 55px;">
                    <img src="auto_selling/霸道辣条.jpg" alt="霸道辣条" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="霸道辣条" data-price="5.9" data-quantity="10">霸道辣条</button>
                </div>
                
                <div class="absolute" style="top: 320px; left: 180px;">
                    <img src="auto_selling/脆香米.jpg" alt="脆香米" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="脆香米" data-price="19.9" data-quantity="8">脆香米</button>
                </div>
                
                <div class="absolute" style="top: 320px; left: 300px;">
                    <img src="auto_selling/大波浪薯片.jpg" alt="大波浪薯片" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="大波浪薯片" data-price="10.9" data-quantity="8">大波浪薯片</button>
                </div>

                <!-- 第四行商品 -->
                <div class="absolute" style="top: 470px; left: 55px;">
                    <img src="auto_selling/乐事薯片.jpg" alt="乐事薯片" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="乐事薯片" data-price="8.8" data-quantity="8">乐事薯片</button>
                </div>
                
                <div class="absolute" style="top: 470px; left: 145px;">
                    <img src="auto_selling/山楂条.jpg" alt="山楂条" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="山楂条" data-price="4.2" data-quantity="8">山楂条</button>
                </div>
                
                <div class="absolute" style="top: 470px; left: 230px;">
                    <img src="auto_selling/饼干.jpg" alt="饼干" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="饼干" data-price="4.2" data-quantity="8">饼干</button>
                </div>
                
                <div class="absolute" style="top: 470px; left: 310px;">
                    <img src="auto_selling/口香糖.jpg" alt="口香糖" class="w-20 h-16 rounded-lg shadow-md mb-1">
                    <button class="bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105" data-name="口香糖" data-price="2.5" data-quantity="8">口香糖</button>
                </div>
                
                <!-- 二维码和付款按钮 -->
                <img id="qrCode" src="auto_selling/qr_code1.png" alt="二维码" class="absolute rounded-lg shadow-md" style="top: 305px; left: 532px; transform: translate(-50%, -50%); width: 135px; height: 135px;">
                <button id="purchaseButton" class="bg-yellow-500 hover:bg-yellow-600 text-black font-bold py-2 px-4 rounded-lg absolute transition-colors duration-200 transform hover:scale-105 shadow-md" style="top: 190px; left: 470px; width: 120px;">
                    <i class="fas fa-shopping-cart mr-2"></i>确认付款
                </button>

                <!-- 商品图片显示区域 -->
                <img id="productImage" src="" alt="商品图片" class="absolute rounded-lg shadow-lg bounce-in" style="top: 725px; left: 246px; transform: translate(-50%, -50%); width: 115px; height: 65px; display: none;">
            </div>
        </div>
    </div>
    
    <script>
        const purchaseButton = document.getElementById('purchaseButton');
        const priceDisplay = document.getElementById('priceDisplay');
        const priceValue = document.getElementById('priceValue');
        const productImage = document.getElementById('productImage');
        const qrCode = document.getElementById('qrCode');
    
        const productButtons = document.querySelectorAll('button[data-name]');
        let productName, productPrice, productQuantity;
    
        // 重置所有按钮的样式
        function resetButtonStyles() {
            productButtons.forEach(button => {
                button.className = 'bg-green-600 hover:bg-green-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105';
            });
        }
    
        // 切换二维码图片
        function toggleQRCodeImage() {
            const currentSrc = qrCode.src;
            if (currentSrc.includes('qr_code1.png')) {
                qrCode.src = 'auto_selling/qr_code2.png';
            } else {
                qrCode.src = 'auto_selling/qr_code1.png';
            }
        }
    
        // 显示通知
        function showNotification(message, type = 'info') {
            const notification = document.createElement('div');
            notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg z-50 transform transition-all duration-300 ${
                type === 'success' ? 'bg-green-600 text-white' :
                type === 'error' ? 'bg-red-600 text-white' :
                'bg-blue-600 text-white'
            }`;
            notification.innerHTML = `
                <div class="flex items-center">
                    <i class="fas ${
                        type === 'success' ? 'fa-check-circle' :
                        type === 'error' ? 'fa-exclamation-circle' :
                        'fa-info-circle'
                    } mr-2"></i>
                    ${message}
                </div>
            `;
    
            document.body.appendChild(notification);
    
            // 动画显示
            setTimeout(() => {
                notification.style.transform = 'translateX(0)';
            }, 100);
    
            // 3秒后自动消失
            setTimeout(() => {
                notification.style.transform = 'translateX(100%)';
                setTimeout(() => {
                    if (notification.parentNode) {
                        notification.parentNode.removeChild(notification);
                    }
                }, 300);
            }, 3000);
        }
    
        productButtons.forEach(button => {
            button.addEventListener('click', () => {
                resetButtonStyles(); // 首先重置所有按钮的样式
                button.className = 'bg-red-600 hover:bg-red-700 text-white text-xs font-medium py-1 px-2 rounded transition-colors duration-200 transform hover:scale-105'; // 设置点击的按钮样式为红色
            
                productName = button.getAttribute('data-name');
                productPrice = parseFloat(button.getAttribute('data-price')).toFixed(2);
                productQuantity = parseInt(button.getAttribute('data-quantity'), 10);
            
                priceValue.textContent = productPrice;
                toggleQRCodeImage(); // 切换二维码图片
            });
        });
    
        purchaseButton.addEventListener('click', () => {
            if (productName) {
                // 显示购买成功通知
                showNotification(`购买成功！商品：${productName}，价格：${productPrice}元`, 'success');
                
                // 显示选中商品的图片
                productImage.src = `auto_selling/${productName}.jpg`; // 设置对应商品的图片路径
                productImage.style.display = 'block'; // 显示图片
                
                // 重置价格显示
                setTimeout(() => {
                    priceValue.textContent = '0.00';
                    productImage.style.display = 'none';
                    resetButtonStyles(); // 重置所有按钮的样式
                    productName = ''; // 清空选中的商品
                }, 3000);
            } else {
                showNotification('请先选择商品', 'error');
            }
        });

    </script>
</body>
</html>
